<?php
namespace models;

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity
 * @DiscriminatorColumn(name="kategori", type="string")
 * @InheritanceType("JOINED")
 */
class Customer extends Akun{

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $jenis_identitas;

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $no_identitas;

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $npwp;

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $telepon_seluler;

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $fax;

	/**
	 * @Column(type="string", nullable=true)
	 */
	protected $keterangan;

	/**
	 * @OneToMany(targetEntity="Kunjungan", mappedBy="customer", cascade={"remove"})
	 */
	protected $kunjungan;

	/**
	 * @ManyToOne(targetEntity="Paket_langganan", inversedBy="customer")
	 * @JoinColumn(name="paket_langganan_id", referencedColumnName="id")
	 */
	protected $paket_langganan;

	/**
	 * @ManyToOne(targetEntity="Agen", inversedBy="customer")
	 * @JoinColumn(name="agen_id", referencedColumnName="id")
	 */
	protected $agen;

    public function __construct($username=null, $password=null, $email=null, $nama=null){
		parent::__construct($username, $password, $email, $nama);
		//if(!$username || $username == '') $this->generate_username();
		$this->kunjungan = new ArrayCollection();
	}

	public function set_jenis_identitas($jenis_identitas){
		$this->jenis_identitas = $jenis_identitas;
		$this->updated = new \DateTime("now");
	}

	public function get_jenis_identitas(){
		return $this->jenis_identitas;
	}

	public function set_no_identitas($no_identitas){
		$this->no_identitas = $no_identitas;
		$this->updated = new \DateTime("now");
	}

	public function get_no_identitas(){
		return $this->no_identitas;
	}

	public function set_npwp($npwp){
		$this->npwp = $npwp;
		$this->updated = new \DateTime("now");
	}

	public function get_npwp(){
		return $this->npwp;
	}

	public function set_telepon_seluler($telepon_seluler){
		$this->telepon_seluler = $telepon_seluler;
		$this->updated = new \DateTime("now");
	}

	public function get_telepon_seluler(){
		return $this->telepon_seluler;
	}

	public function set_fax($fax){
		$this->fax = $fax;
		$this->updated = new \DateTime("now");
	}

	public function get_fax(){
		return $this->fax;
	}

	public function set_keterangan($keterangan){
		$this->keterangan = $keterangan;
		$this->updated = new \DateTime("now");
	}

	public function get_keterangan(){
		return $this->keterangan;
	}

	public function add_kunjungan(Kunjungan $kunjungan){
		$this->kunjungan[] = $kunjungan; 
		//$this->updated = new \DateTime("now");
	}

	public function get_kunjungan(){
		return $this->kunjungan;
	}

	public function set_paket_langganan(Paket_langganan $pl){
		$pl->add_customer($this);
		$this->paket_langganan = $pl;
		$this->updated = new \DateTime("now");
	}

	public function get_paket_langganan(){
		return $this->paket_langganan;
	}

	public function set_agen(Agen $agen){
		$agen->add_customer($this);
		$this->agen = $agen;
		$this->updated = new \DateTime("now");
	}

	public function get_agen(){
		return $this->agen;
	}

	public function get_kategori(){
		$kategori = get_class($this);
		if ($kategori == 'Customer') $kategori = 'pribadi';
		else $kategori == 'perusahaan';
		return $kategori;
	}

	static public function get_dropdown_options(){

		$CI =& get_instance();

		$customer = $CI->doctrine->em
			->createQuery('SELECT c FROM models\Customer c ORDER BY c.username ASC')
			->getResult();

		$option_customer = array();
		foreach($customer as $c){
			$option_customer[$c->get_id()] = $c->get_username().' - '.$c->get_nama();
		};

		return $option_customer;
	}
}
